import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        token: '',
        // activeRouterPath: window.localStorage.getItem('activeRouterPath' || '') == null ? null : window.localStorage.getItem('activeRouterPath' || ''),
        menuList: [],
        user: window.localStorage.getItem('user') == null ? null : JSON.parse(window.localStorage.getItem('user'))
    },
    mutations: {
        //设置 token
        set_user(state, data) {
            state.user = data
        },
        //设置 token
        set_token(state, token) {
            state.token = token
            localStorage.token = token
        },
        //删除 token
        del_token(state) {
            state.token = ''
            localStorage.removeItem('token')
        },

        //设置权限菜单列表
        set_menuList(state, menuList) {
            state.menuList = menuList
        },
        //删除权限菜单列表
        del_menuList(state) {
            state.menuList = []
        },

        // set_active_path(state, path) {
        //     state.activeRouterPath = path
        //     localStorage.activeRouterPath = path
        // },

        //退出
        exit_logout(state){
            state.token = ''
            state.user = null
            // state.activeRouterPath = ''

            localStorage.removeItem('token');
            localStorage.removeItem('user');
            localStorage.removeItem('activeRouterPath');
            // localStorage.clear();
        },

    },
    actions: {

    }
})